package com.cskaoyan;

import com.mysql.jdbc.Driver;

import java.sql.*;

// 增
public class InsertDBCDemo {

    public static void main(String[] args) throws SQLException {



        // 注册驱动
        DriverManager.registerDriver(new Driver());

        String url = "jdbc:mysql://localhost:3306/34th?useSSL=false";
        String username = "root";
        String password = "123456";

        // 获取连接 其实就是建立Java应用程序和数据库之间的连接
        Connection connection = DriverManager.getConnection(url, username, password);

        // 获取Statement对象  这个对象是用来把SQL语句包装成网络请求并发送的，并且返回执行的结果
        Statement statement = connection.createStatement();

        int affectedRows = statement.executeUpdate("insert into stu values (6,'李云龙','三班')");

        System.out.println("affectedRows:" + affectedRows);

        // 释放资源
        try {

        }finally {
            try {
                statement.close();
            }finally {
                connection.close();
            }
        }

    }
}
